﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DAL.Entities;

namespace DAL.EntitesDAL
{
    public class VaitroDAL : BaseDAL, UTL.IBaseDAL
    {
        #region Implement

        public int Count()
        {
            throw new NotImplementedException();
        }

        public DataTable Select()
        {
            return ExecuteQuery("sp_SelectAll_Vaitro");
        }

        public DataTable Select(object obj)
        {
            throw new NotImplementedException();
        }

        public object GetByKey(object key)
        {
            throw new NotImplementedException();
        }

        public bool Delete(string id)
        {
            throw new NotImplementedException();
        }

        public bool Delete(long id)
        {
            var sql = "sp_Delete_Vaitro {0}";
            sql = string.Format(sql, id);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Insert(object obj)
        {
            var o = (VaiTro)obj;
            var sql = "set dateformat dmy; execute sp_Insert_Vaitro N'{0}', N'{1}' ";
            sql = string.Format(sql, o.Ten, o.Mota);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Update(object obj)
        {
            var o = (VaiTro)obj;
            var sql = "set dateformat dmy; execute sp_Update_Vaitro '{0}', N'{1}', N'{2}' ";
            sql = string.Format(sql, o.Id, o.Ten, o.Mota);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public DataTable Search(string name)
        {
            var sql = @"select * from tb_Vaitro where Ten like N'%{0}%' ";
            sql = string.Format(sql, name);
            return ExecuteQuery(sql);
        }


        #endregion
    }
}
